package org.finesys.common.hazelcast.core.support;

import com.hazelcast.cp.ICountDownLatch;
import lombok.RequiredArgsConstructor;
import org.finesys.common.hazelcast.core.base.DistributedCountDownLatch;

import java.util.concurrent.TimeUnit;

@RequiredArgsConstructor
public class HazelcastCountDownLatch implements DistributedCountDownLatch {

    private final ICountDownLatch countDownLatch;

    @Override
    public boolean await(long timeout, TimeUnit timeUnit) throws InterruptedException {
        return countDownLatch.await(timeout, timeUnit);
    }

    @Override
    public void countDown() {
        countDownLatch.countDown();
    }

    @Override
    public int getCount() {
        return countDownLatch.getCount();
    }

    @Override
    public boolean trySetCount(int count) {
        return countDownLatch.trySetCount(count);
    }

    @Override
    public void destroy() {
        countDownLatch.destroy();
    }

    @Override
    public String getName() {
        return countDownLatch.getName();
    }
}
